﻿/*--------------------------------------------------------------
 * Author : Shine K Velayudhan 
 ---------------------------------------------------------------*/
using System;
using System.Collections;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;

namespace IQN.Logging
{
    [AttributeUsage(AttributeTargets.Method)]
    public class LoggerMethodAttribute : Attribute
    {
        private MessageType messageType;
        public  MessageLevel MethodLevel { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string ClassName { get; set; }
        public string MethodName { get; set; }
        public string Param1 { get; set; }
        public string Param2 { get; set; }
        public LoggerMethodAttribute(MessageType messageType) 
        {
            this.messageType = messageType;
        }
        public void Log(IMethodMessage msg)
        {
            ILogger logger = LogManager.GetLogger(this.GetType());
            switch (messageType)
            {
                case MessageType.Performance:
                    logger.Log(MessageLevel.Info, ClassName, MethodName, StartTime, EndTime, Param1, Param2);
                    foreach (var message in LogDataManager.PerformanceMessages)
                        Console.WriteLine(message.MessageText);
                    break;
            }
            
        }
        public bool IsContextOK(Context ctx, System.Runtime.Remoting.Activation.IConstructionCallMessage msg)
        {
            return false;
        }
    }
}
    



